package com.anytrek.clouduser.controller;

import com.anytrek.cloudcommon.entity.UsersEntity;
import com.anytrek.cloudcommon.utils.ApiResult;
import com.anytrek.clouduser.service.UsersService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ ClassName UsersController
 * @ Author Alex2
 * @ Date 2025/8/22 12:26
 **/
@RestController
@RequestMapping("/users")
@RequiredArgsConstructor
public class UsersController {

    private final UsersService usersService;

    // http://localhost:8881/users/insertUser?username=Alex&password=123456&age=18&balance=500
    @GetMapping("insertUser")
    public ApiResult insertUser(@RequestParam("username") String username,
                                @RequestParam("password") String password,
                                @RequestParam("age") Integer age,
                                @RequestParam("balance") Integer balance) {
        return usersService.insertUser(username, password, age, balance);
    }

    // http://localhost:8881/users/getUserById?id=1
    @GetMapping("getUserById")
    public ApiResult getUserById(@RequestParam("id") Integer id) {
        return usersService.getUserById(id);
    }

    @GetMapping("deductBalance")
    public ApiResult deductBalance(@RequestParam("id") Integer id,
                                   @RequestParam("amount") Integer amount) {
        return usersService.deductBalance(id, amount);
    }
}